<?php
/**
 * 前后台公用
 * Created by PhpStorm.
 * User: 武 斌
 * Date: 2016/12/13
 * Time: 14:31
 */

namespace Common\Controller;


use Think\Controller;

class BaseController extends Controller
{
	public function __construct()
	{
		parent::__construct();
		if( method_exists( $this , '__init' ) ) {
			$this->__init();
		}
	}

	//添加
	public function store( Model $model , $data , \Closure $callback = null )
	{
		$res = $model->store( $data );
		if( $res['status'] == 'success' && $callback instanceof \Closure ) {
			$callback($res);
		}
		$this->message( $res );
	}

	//提示消息
	public function message( $data )
	{
		if( $data['status'] == 'success' ) {
			//说明成功
			$this->success( $data['message'] );
			exit;
		} else {
			$this->error( $data['message'] );
			exit;
		}
	}
}